<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>还款列表</title>
</head>

<body>
<div class="layui-fluid">
	<div style="height:11px;"></div>
	<blockquote class="layui-elem-quote">
		<div class="layui-form">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">关键字</label>
					<div class="layui-input-inline">
						<input name="keywords" type="text"  class="layui-input" placeholder="输入会员名称、电话、计划单号" style=" width:215px" />
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">计划状态</label>
					<div class="layui-input-inline">
						<select name="state" id="state" style=" width:100px">
							<option value="">--全部类别--</option>
							<option value="1">--计划进行中--</option>
							<option value="2">--计划已完成--</option>
							<option value="3">--计划失败--</option>
							<option value="4">--用户终止计划--</option>
							<option value="6">--后台关闭计划--</option>
							<option value="7">--异常订单--</option>
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">支付状态</label>
					<div class="layui-input-inline">
						<select name="type" id="type" style=" width:100px">
							<option value="">--全部类别--</option>
							<option value="0">--正常--</option>
							<option value="1">--需补单--</option>
							<option value="2">--失败--</option>
							<option value="3">--支付中--</option>
						</select>
					</div>
				</div>

				<div class="layui-inline">
					<label class="layui-form-label">支付通道</label>
					<div class="layui-input-inline">
						<select name="pay_id" id="pay_id" style=" width:100px">
							<option value="">--全部通道--</option>
							<option value="2">--小额通道--</option>
							<option value="7">--大额通道--</option>
							<option value="8">--新大额通道--</option>
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">时间</label>
					<div class="layui-input-inline">
						<input type="text" name="query_date" id="query_date" autocomplete="off" class="layui-input" readonly="readonly">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">明细订单号</label>
					<div class="layui-input-inline">
						<input type="text" name="plan_form_no" class="layui-input" placeholder="输入账单明细订单号" />
					</div>
				</div>
				<div class="layui-inline">
					<div class="layui-input-inline">
						<button class="layui-btn" lay-submit lay-filter="sub">查询</button>
					</div>
				</div>
			</div>
		</div>
	</blockquote>

	<blockquote class="layui-elem-quote">
		以下所有数据在没有选择日期范围的时候就是总数据，如果选择日期范围那么就是日期范围内的总数据<br>
		还款总额：<span id="total">0</span>元 <br>
		总手续费：<span id="total_fee">0</span>元 <br>
		手续费利润：<span id="total_fee_profit">0</span>元<br>
	</blockquote>


	<div id="table" lay-filter="table" class="layui-table"></div>


	<!-- tpl区域 -->
	<script type="text/html" id="bar">
		<a class="layui-btn layui-btn-xs" lay-event="detail">计划明细</a>
		<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="close">关闭计划</a>
		<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="restart" title="重新启动计划">重启计划</a>
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除计划</a>
	</script>

	<script type="text/html" id="mission_current_state">
		{{#  if(d.mission_current_state == '1'){  }}
		<a class="layui-btn layui-btn-xs layui-btn-danger">还款</a>
		{{#  }else if(d.mission_current_state == '2'){  }}
		<a class="layui-btn layui-btn-xs">消费</a>
		{{# } }}
	</script>


</div>
<link href="__PLUS__/layui/css/layui.css" rel="stylesheet"/>
<script src="__PLUS__/layui/layui.js"></script>
<script>
	layui.use(["jquery", "form", "layer", "table", "laydate"], function () {
		var $ = layui.jquery, layer = layui.layer, table = layui.table, form = layui.form,laydate=layui.laydate;

		laydate.render({
			elem:"#query_date",
			range:true
		});

		var options = {
			elem: '#table',
			url: "{:url('index')}", //数据接口
			cols: [[ //表头
				{type: "checkbox"},
				{field: 'mission_id', title: 'ID'},
				{field: 'payment_name', title: '通道',width:120},
				{field: 'mission_form_no', title: '计划单号',width:220},
				{field: 'user_name', title: '用户',width:80},
				{field: 'user_phone', title: '手机',width:120},
				{field: 'mission_money', title: '还款金额',width:100},

				{field: 'mission_at_fee', title: '当前手续费',width:100},
				//{field: 'mission_start_time', title: '开始时间',width:110},
				//{field: 'mission_end_time', title: '结束时间',width:110},
				{field: 'mission_pay_time', title: '执行时间',width:160},
				//{field: 'mission_close_rate', title: '费率'},
				{field: 'list_name', title: '银行名称',width:100},
				{field: 'mission_current_state', title: '当前订单状态',templet:"#mission_current_state",width:100},
				{field: 'mission_state', title: '状态',width:180},
				{field: 'mission_fee', title: '总手续费',width:100},
				{field: 'mission_repayment_number', title: '还款笔数'},
				{field: 'mission_consume_number', title: '消费笔数'},
				{title: '操作', toolbar: "#bar",fixed:"right",width:300},
			]],
			page: true, //开启分页
			loading: true,
			limit: 10,
			done:function(res, curr, count){
				//console.log(res);
				$("#total").text(res.totalMoney);
				$("#total_fee").text(res.totalFee);
				$("#total_fee_profit").text(res.totalFeeProfit);
				//$("#total_df").text(res.totaldfFee);
				//$("#total_df_profit").text(res.totaldfFeeProfit);
				//$("#total_profit").text(res.totalProfit);
			}
		};
		var tableIns = table.render(options);

		//搜索提交
		form.on("submit(sub)", function (res) {
			var data = res.field;
			//console.log(data);
			options["where"] = data;
			tableIns.reload(options);
			return false;
		});


		table.on('tool(table)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
			var data = obj.data; //获得当前行数据
			var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
			//alert(obj.event);return false;
			if (layEvent === 'detail') { //查看
				var url = "{:Url('detail')}?id="+data.mission_id
				layer.open({
					type:2,
					title:"计划明细",
					area: ['80%', '80%'],
					content:url
				});
			} else if (layEvent === 'close') { //关闭计划
				layer.confirm("确定要关闭计划吗？", function () {
					$.get("{:Url('Admin/Repayment/close')}", {id: data.mission_id,type:1}, function (res) {
						if (res.msg != '') {
							layer.msg(res.msg);
						}
						// if (res.url != '') {
						// 	window.location.href = res.url;
						// }
					});
				});
			} else if (layEvent === 'del') { //查看
				layer.confirm("确定要删除计划吗？", function () {
					$.get("{:Url('Admin/Repayment/del')}", {id: data.mission_id}, function (res) {
						if (res.msg != '') {
							layer.msg(res.msg);
						}
						// if (res.url != '') {
						// 	window.location.href = res.url;
						// }
					});
				});
			}else if(layEvent == "restart"){
				layer.confirm("确定要重启计划吗？", function () {
					$.get("{:Url('Admin/Repayment/restart')}", {id: data.mission_id}, function (res) {
						if (res.msg != '') {
							layer.msg(res.msg);
						}
						// if (res.url != '') {
						// 	window.location.href = res.url;
						// }
					});
				});
			}
		});
	});
</script>
</body>

</html>